/******************************************************************************
 * CeriacrudwicketDaoImpl.java - created by Sakai App Builder -AZ
 * 
 * Copyright (c) 2008 Sakai Project/Sakai Foundation
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 * 
 *****************************************************************************/

package com.ptsolusi.ceriacrudwicket.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import org.sakaiproject.genericdao.hibernate.HibernateGeneralGenericDao;

import com.ptsolusi.ceriacrudwicket.dao.CeriacrudwicketDao;
import com.ptsolusi.ceriacrudwicket.model.Customer;
import com.ptsolusi.ceriacrudwicket.model.OrderH;

/**
 * Implementations of any specialized DAO methods from the specialized DAO that
 * allows the developer to extend the functionality of the generic dao package
 * 
 * @author Sakai App Builder -AZ
 */
public class CeriacrudwicketDaoImpl extends HibernateGeneralGenericDao
		implements CeriacrudwicketDao {

	private static Log log = LogFactory.getLog(CeriacrudwicketDaoImpl.class);

	public void init() {
		log.debug("init");
	}

	@SuppressWarnings("unchecked")
	public List<Customer> getAllCustomer() {
		DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);
		criteria.addOrder(Order.asc("id"));
		List<Customer> customerList = getHibernateTemplate().findByCriteria(criteria);
		return customerList;
	}

	@SuppressWarnings("unchecked")
	public List<Customer> getCustomersByFirstName(String firstName) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);
		criteria.add(Restrictions.or(Restrictions.ilike("firstName", firstName), Restrictions.ilike("lastName", firstName)));
		criteria.addOrder(Order.asc("id"));
		return getHibernateTemplate().findByCriteria(criteria);
	}

	public List<OrderH> getAllOrder() {
		return findAll(OrderH.class);
	}
}
